<?php
/*
通知管理
*/
namespace Home\Controller;
use Think\Controller;
class ArticleController extends CommonController{

  //通知首页
    public function index(){
      $con =array('state'=>'0');
      $data = D('News') -> selectNews($con);
      $num = D('News') -> countNews($con);
      $this->assign('num',$num);
      $this->assign('news' , $data);
      $user = session('USER_AUTH');
      $this->assign('user',$user);
      $this->display('Article/index');
    }


    public function articleadd(){
      $this->display('Article/article-add');
    }


    public function articlealert(){
      $id = I('get.id');
      $news = D('News') -> findData($id);
      $this->assign('news' , $news);
      $this->display('Article/article-alert');
    }

    public function articleview(){
      $id = I('get.id');
      $news = D('News') -> findData($id);
      $this->assign('news' , $news);
      $this->display('Article/article-view');
    }


    public function addCheck(){
      if(IS_POST){
        $point_id = D('Point') -> addPoint('Article/addCheck', '添加通知');//功能节点id
        $roleid = session('USER_AUTH.roleid');//权限角色id
        if( haveAblitity($point_id , $roleid) ){
          $data['title'] = I('post.title');
          $data['content'] = I('post.content');
          $data['create_time'] = timeStrop(I('post.time'));
          $data['state'] = '0';
          if($data['title'] && I('post.time') && $data['content']){
            $news = D('News') -> addNews($data);
            if($news){
              $this->jsonReply('200' , '添加成功');
            }
            else{
              $this->jsonReply('500' , '添加失败');
            }
          }
          else{
            $this->jsonReply('500' , '请填写完整');
          }
        }
        else{
          $this -> jsonReply('500' , '您没有权限操作此功能');
        }
      }
    }

    public function editCheck(){
      if(IS_POST){
        $point_id = D('Point') -> addPoint('Article/editCheck', '编辑通知');//功能节点id
        $roleid = session('USER_AUTH.roleid');//权限角色id
        if( haveAblitity($point_id , $roleid) ){
          $newsid = I('post.newsid');
          $data['title'] = I('post.title');
          $data['content'] = I('post.content');
          $data['create_time'] = timeStrop(I('post.time'));
          $data['state'] = '0';
          if($data['title'] && I('post.time') && $data['content']){
            $news = D('News') -> saveNews($newsid , $data);
            if($news){
              $this->jsonReply('200' , '保存成功');
            }
            else{
              $this->jsonReply('500' , '请填写修改内容');
            }
          }
          else{
            $this->jsonReply('500' , '请填写完整');
          }
        }
        else{
          $this -> jsonReply('500' , '您没有权限操作此功能');
        }
      }
    }

//
    public function delCheck(){
      if(IS_POST){
        $point_id = D('Point') -> addPoint('Article/delCheck', '删除通知');//功能节点id
        $roleid = session('USER_AUTH.roleid');//权限角色id
        if( haveAblitity($point_id , $roleid) ){
          $newsid = I('post.newsid');
          $news = D('News') -> saveNews($newsid ,array('state'=>'2'));
          if($news){
            $this->jsonReply('200' , '删除成功');
          }
          else{
            $this->jsonReply('500' , '删除失败');
          }
        }
        else{
          $this -> jsonReply('500' , '您没有权限操作此功能');
        }
      }
    }

    public function delDatas(){
      if(IS_POST){
        $point_id = D('Point') -> addPoint('Article/delDatas', '批量删除通知');//功能节点id
        $roleid = session('USER_AUTH.roleid');//权限角色id
        if( haveAblitity($point_id , $roleid) ){
          $id = I('post.id');
          if(count($id)==1){
            $del = D('News') -> saveNews($id[0],array('state'=>'2'));
          }
          if(count($id)>1){
            foreach($id as $k=>$v){
              $del = D('News') -> saveNews($v,array('state'=>'2'));
            }
          }
          if($del){
            $this -> jsonReply('200' , '删除成功');
          }
          else{
            $this -> jsonReply('500' , '删除失败');
          }
        }
        else{
          $this -> jsonReply('500' , '您没有权限操作此功能');
        }
      }
    }








}
